package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Publish;
import com.tanhua.server.service.MovementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/movements")
public class MoveMentsController {

    @Autowired
    private MovementService movementService;

    @PostMapping
    public ResponseEntity<Object> movements(Publish publish, MultipartFile[] imageContent) throws IOException {
        return movementService.publishMovement(publish,imageContent);
    }

    @GetMapping
    public ResponseEntity<Object> queryMovements(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize){
        return movementService.queryMovements(page,pagesize);
    }

    @GetMapping("/recommend")
    public ResponseEntity<Object> recommend(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize){
        return movementService.recommend(page,pagesize);
    }

    @GetMapping("/all")
    public ResponseEntity<Object> all(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize, @RequestParam Long userId){
        return movementService.all(page,pagesize,userId);
    }

    @GetMapping("{id}/like")
    public ResponseEntity<Object> likeComment(@PathVariable("id") String publishId) throws NoSuchFieldException, IllegalAccessException {
        return movementService.likeComment(publishId);
    }

    @GetMapping("{id}/dislike")
    public ResponseEntity<Object> dislikeComment(@PathVariable("id") String publishId) throws NoSuchFieldException, IllegalAccessException {
        return movementService.dislikeComment(publishId);
    }

    @GetMapping("{id}/love")
    public ResponseEntity<Object> love(@PathVariable("id") String publishId) throws NoSuchFieldException, IllegalAccessException {
        return movementService.love(publishId);
    }

    @GetMapping("{id}/unlove")
    public ResponseEntity<Object> unlove(@PathVariable("id") String publishId) throws NoSuchFieldException, IllegalAccessException {
        return movementService.unlove(publishId);
    }

    @GetMapping("{id}")
    public ResponseEntity<Object> singleMovement(@PathVariable("id") String publishId){
        return movementService.singleMovement(publishId);
    }

    @GetMapping("/visitors")
    public ResponseEntity<Object> visitors(){
        return movementService.queryVisitors();
    }


}
